package com.share.web.action.sysmgr;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.json.annotations.JSON;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.share.bean.sysmgr.BackTreeMenu;
import com.share.service.sysmgr.BackTreeMenuManager;
import com.share.web.action.base.BaseActionSupport;
import com.share.web.formbean.sysmgr.BackTreeMenuForm;

@Controller
@Scope("prototype")
public class BackTreeMenuAction extends BaseActionSupport{

	private static final long serialVersionUID = 1L;

	private BackTreeMenu tree ;
	
	private BackTreeMenuForm treeform ;
	
	private List<BackTreeMenu> treeRootJson ;
	
	@Resource
	private BackTreeMenuManager treeMgr ;
	
	/**
	 * 保存树状
	 * @return
	 * @throws Exception
	 */
	public String saveTree() throws Exception {
		
		try {
			this.treeMgr.saveBackTreeMenuManager(tree) ;
		} catch (Exception e) {
			e.printStackTrace() ;
		}
		return "pub_add_success" ;
	}
	
	/**
	 * 查找所有菜单根
	 * @return
	 * @throws Exception
	 */
	public String findTreeRootPage() throws Exception {
		
		this.getBaseform().getRequest().setAttribute("tree", this.treeMgr.findBackTreeMenuManager(tree,treeform)) ;
		return "findTreeRootPage" ;
	}
	
	/**
	 * 查找所有菜单根
	 * @return JSON
	 * @throws Exception
	 */
	public String findTreeRootJson() throws Exception {
		
		treeRootJson = this.treeMgr.findBackTreeMenuManager(tree,treeform) ;
		return "findTreeRootJson" ;
	}
	
	
	public List<BackTreeMenu> getTreeRootJson() {
		return treeRootJson;
	}

	public void setTreeRootJson(List<BackTreeMenu> treeRootJson) {
		this.treeRootJson = treeRootJson;
	}

	@JSON(deserialize=false,serialize=false)
	public BackTreeMenu getTree() {
		return tree;
	}

	public void setTree(BackTreeMenu tree) {
		this.tree = tree;
	}

	@JSON(deserialize=false,serialize=false)
	public BackTreeMenuManager getTreeMgr() {
		return treeMgr;
	}

	public void setTreeMgr(BackTreeMenuManager treeMgr) {
		this.treeMgr = treeMgr;
	}
	
	@JSON(deserialize=false,serialize=false)
	public BackTreeMenuForm getTreeform() {
		return treeform;
	}

	public void setTreeform(BackTreeMenuForm treeform) {
		this.treeform = treeform;
	}
}
